package com.huangsm.concurrence.executor;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 执行器服务submit(Runnable)
 * @author huang
 * @date 2019/2/14
 */
public class ExecutorServiceDemo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //submit(Runnable) 方法也要求一个 Runnable 实现类，但它返回一个 Future 对象。这个 Future 对象可以用来检查 Runnable 是否已经执行完毕。
        ExecutorService executorService= Executors.newFixedThreadPool(10);
        Future<?> future = executorService.submit(() -> {
            System.out.println("异步任务");
        });
        Object o = future.get();
        System.out.println(o);// //returns null if the task has finished correctly.
    }
}
